package com.ulook.lookplanet.data.source;

import com.ulook.lookplanet.common.AppServer;
import com.ulook.lookplanet.data.model.TArticle;
import com.ulook.lookplanet.ui.square.pub.PubArticleInfo;
import com.ulook.lookplanet.util.net.AsynRequestUtil;
import com.ulook.lookplanet.util.net.RequestParams;
import com.ulook.lookplanet.util.net.ResponseCallback;

import java.io.File;
import java.util.List;

/**
 * 描述：
 *
 * @author L1998
 * @data 2021/4/6
 */
public class PubDataSource {


    /**
     * 上传图片
     */
    public void pub(PubArticleInfo pubArticleInfo, ResponseCallback callback){
        RequestParams params = new RequestParams();

        TArticle article = pubArticleInfo.getArticle();
        File audio = pubArticleInfo.getAudioFile();
        List<File> imageList = pubArticleInfo.getPicFileList();
        if(audio != null){
            imageList.add(0, audio);
            params.put("audio", article.getAudrofile());
        }
        params.put("uid", article.getUid());
        params.put("userId", article.getAuthor());
        params.put("content", article.getContent());
        params.put("hasPic", article.getHaspic());
        params.put("comuId", article.getComuid());
        params.put("hasTopic", article.getHastopic());

        AsynRequestUtil.postMultipart(AppServer.ROOT_PATH + "/pub/pubArticle", params, imageList, null, callback);

        if(audio != null){
            imageList.remove(0);
        }
    }
}
